/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.tedu.luban.account.main.controller;


import cn.tedu.luban.account.main.converter.AccountConverter;
import cn.tedu.luban.account.main.service.AccountAdminService;
import cn.tedu.luban.account.protocol.VO.AccountVO;
import cn.tedu.luban.account.protocol.bo.AccountBO;
import cn.tedu.luban.account.protocol.query.AccountQuery;
import com.tedu.inn.protocol.ListRecordTotalBO;
import com.tedu.inn.protocol.exception.BusinessException;
import com.tedu.inn.protocol.model.Result;
import com.tedu.inn.protocol.pager.PagerResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "account",tags = "账户接口")
@RestController
@RequestMapping("admin/account")
public class AccountAdminController {

    @Autowired
    private AccountAdminService accountService;

    @Autowired
    private AccountConverter accountConverter;

    @PostMapping(value = "search",produces = "application/json")
    @ResponseBody
    @ApiOperation("账户列表")
    public Result<PagerResult<AccountVO>> queryAccounts(@RequestBody AccountQuery accountQuery) {
        ListRecordTotalBO<AccountBO> accountListTotalRecord = this.accountService.queryAccount(accountQuery);
        return new Result(this.accountConverter.bo2PagerResultVO(accountListTotalRecord, accountQuery));
    }

    @PostMapping("enable")
    @ApiOperation("解冻")
    public Result<Integer> enableAccount(@RequestParam  Long id) throws BusinessException {
        return new Result(this.accountService.enableAccount(id));
    }

    @PostMapping("disable")
    @ApiOperation("冻结")
    public Result<Integer> disableAccount(@RequestParam Long id) throws BusinessException {
        return new Result(this.accountService.disableAccount(id));
    }
}